package com.daoeping.action;

import java.util.ArrayList;
import java.util.List;

import com.daoeping.data.Usr_friend;
import com.daoeping.data.Usr_user;
import com.daoeping.domain.JsonData;
import com.daoeping.domain.Page;
import com.daoeping.service.Usr_friendService;
import com.daoeping.util.ConverntJsonData;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class Usr_friendAction extends ActionSupport{
	private Usr_friend usr_friend;
	private Usr_friendService usr_friendService;
	private JsonData jsonData;
	private Page page;
	
	public Page getPage() {
		return page;
	}

	public void setPage(Page page) {
		this.page = page;
	}

	public JsonData getJsonData() {
		return jsonData;
	}

	public void setJsonData(JsonData jsonData) {
		this.jsonData = jsonData;
	}

	public Usr_friendService getUsr_friendService() {
		return usr_friendService;
	}

	public void setUsr_friendService(Usr_friendService usr_friendService) {
		this.usr_friendService = usr_friendService;
	}

	public Usr_friend getUsr_friend() {
		return usr_friend;
	}

	public void setUsr_friend(Usr_friend usr_friend) {
		this.usr_friend = usr_friend;
	}
	public String addUsr_friend(){
		//add user id
		System.out.println(usr_friend.getUsr_friendgroup().getId());
		System.out.println(usr_friend.getUsr_userByFriendId().getId());
		System.out.println(usr_friend.getUsr_userByUserId().getId());
		usr_friend.setUsr_userByUserId((Usr_user)ActionContext.getContext().getSession().get("user"));
		if(usr_friendService.addUsr_friend(usr_friend)){
			return "addUsr_friend";
		}else{
			return "exception";
		}
	}
	
	public String findUsr_friendList(){
		jsonData = new JsonData();
		List<Usr_user> usr_userList = (List<Usr_user>)usr_friendService.findUsr_friendList((Usr_user)ActionContext.getContext().getSession().get("user"));
		List <String[]> strList = new ArrayList<String[]>();
		for (Usr_user usr_user : usr_userList) {
			String [] strarr = new String[2];
			strarr[1] = usr_user.getId()+"";
			strarr[0] = usr_user.getUsername();
			strList.add(strarr);
		}
		jsonData.setJsonData( new ConverntJsonData().getJsonData(strList)+"");
		System.err.println(jsonData.getJsonData());
		return "findUsr_friendList";
	}
	
	
}
